//
//  JXHEmoticonPackage.swift
//  emojeTest
//
//  Created by juxiaohui on 16/11/1.
//  Copyright © 2016年 juxiaohui. All rights reserved.
//

import UIKit

class JXHEmoticonPackage: NSObject {

    
    var emoticons : [JXHEmoticon] = [JXHEmoticon]()
    
    
    init(id : String) {
        
        if id == "" {//最近
            
            //添加空白表情
            let count = emoticons.count % 21
            
            for _ in count..<20 {
                
                emoticons.append(JXHEmoticon.init(isEmpty: true))
            }
            emoticons.append(JXHEmoticon.init(isRemove: true))

            return
        }
        
        //根据id拼接info.plist的路径
        
        let path = Bundle.main.path(forResource: "\(id)/info.plist", ofType: nil, inDirectory: "Emoticons.bundle")!
        //根据info.plist的路径获取数据
        let dic = NSDictionary.init(contentsOfFile: path)! as! [String : Any]
        
        //获得表情数组
        let array = dic["emoticons"] as! [[String : String]]
        
        var index = 0

        for var dic in array {
            
            if let png = dic["png"] {
              dic["png"] = id + "/" + png
            }
            emoticons.append(JXHEmoticon.init(dic: dic))
            index += 1
            
            if index == 20 {
                emoticons.append(JXHEmoticon.init(isRemove: true))
                index = 0
            }
        }
        
        let count = emoticons.count % 21
        
        if count == 0 {
            return
        }
        
        for _ in count..<20 {
            
            emoticons.append(JXHEmoticon.init(isEmpty: true))
        }
        emoticons.append(JXHEmoticon.init(isRemove: true))

    }

    
}













